LEN Function ---------------------------------------------------------------------------- Action Returns the number of characters in a string or the number of bytes required by a variable. Syntax 1 LEN( stringexpression$) Syntax 2 LEN( variable) Remarks In the first form, LEN returns the number of characters in the argument stringexpression$. The second syntax returns the number of bytes required by a BASIC variable. This syntax is particularly useful for determining the correct record size of a random-access file. When you pass a string length as an argument to a procedure that may change the value of the argument, be sure to pass it by value instead of by reference, which is the BASIC default. Do this by placing parentheses around LEN(N$), e.g.,(LEN(N%)). Alternatively, you can use a temporary variable, e.g. N% = LEN(N$), and pass the temporary variable in the standard way. Failure to use these techniques will corrupt string space if you change the value of the passed argument. Example The following example prints the length of a string and the size in bytes of several types of variables. CLS ' Clear screen. TYPE EmpRec EmpName AS STRING * 20 EmpNum AS INTEGER END TYPE DIM A AS INTEGER, B AS LONG, C AS SINGLE, D AS DOUBLE DIM E AS EmpRec PRINT "A string." LEN("A string.") PRINT "Integer." LEN(A) PRINT "Long." LEN(B) PRINT "Single." LEN(C) PRINT "Double." LEN(D) PRINT "EmpRec." LEN(E) END Output A string. 9 Integer. 2 Long. 4 Single. 4 Double. 8 EmpRec. 22